import PageDialog from '@/components/PageDialog/index.vue';
import PageEmptyData from '@/components/PageEmptyData/index.vue';
import deleteDialog from '@/components/deleteDialog.vue';
import auditDialog from '@/components/auditDialog.vue';
export default {
  components: { auditDialog, PageEmptyData, PageDialog, deleteDialog },
  data() {
    return {
      maxDate: null, // 动态最大可选日期
      // 限制选择范围不超过30天
      pickerOptions: {
        onPick: range => {
          if (range && range.minDate) {
            const maxTime = range.minDate.getTime() + 30 * 24 * 60 * 60 * 1000;
            this.maxDate = new Date(maxTime);
          } else {
            this.maxDate = null;
          }
        },
        disabledDate: date => {
          // 如果没有设置maxDate，则不禁用任何日期
          if (!this.maxDate || !date) {
            return false;
          }
          // 禁用超过30天范围的日期
          return date > this.maxDate;
        }
      },
      // 限制选择范围不超过12个月
      pickerOptions1: {
        onPick: range => {
          if (range && range.minDate) {
            const maxTime = range.minDate.getTime() + 365 * 24 * 60 * 60 * 1000;
            this.maxDate = new Date(maxTime);
          } else {
            this.maxDate = null;
          }
        },
        disabledDate: date => {
          // 如果没有设置maxDate，则不禁用任何日期
          if (!this.maxDate || !date) {
            return false;
          }
          // 禁用超过12个月范围的日期
          return date > this.maxDate;
        }
      },
      // 限制选择范围不超过6年
      pickerOptions2: {
        onPick: range => {
          if (range && range.minDate) {
            const maxTime = range.minDate.getTime() + 6 * 365 * 24 * 60 * 60 * 1000;
            this.maxDate = new Date(maxTime);
          } else {
            this.maxDate = null;
          }
        },
        disabledDate: date => {
          // 如果没有设置maxDate，则不禁用任何日期
          if (!this.maxDate || !date) {
            return false;
          }
          // 禁用超过6年范围的日期
          return date > this.maxDate;
        }
      },
      applyOptions: [{ value: 1, label: '公共' }],
      tableHeight: 300, //表格高度
      addDialogVisible: false, //显示添加弹窗
      deleteDialogVisible: false, //删除弹窗
      auditDialogVisible: false, //审核弹窗
      tableData: [], //表格数据
      selectedRow: null, //当前选择的表格数据
      multipleSelection: [] //选中的表格数据
    };
  },
  computed: {
    roleType() {
      //1:超级管理员 2:普通管理员 3:普通员工
      return this.$store.state?.userInfo?.roleType;
    }
  },
  created() {
    if (this.roleType === 1) {
      this.applyOptions.push({ value: 4, label: '待审核' });
    } else {
      this.applyOptions.push({ value: 2, label: '自建' });
    }
  },
  methods: {
    //计算表格的高度
    calculateTableHeight() {
      this.$nextTick(() => {
        const el = this.$refs.pubTableRef;
        const dimensions = this.$rules.getFullDimensions(el);
        const pageinationEl = this.$refs.pubPageinationRef;
        const pageinationDimensions = (pageinationEl && this.$rules.getFullDimensions(pageinationEl)) || 0;
        const maxTableHeight = dimensions.contentHeight - (pageinationDimensions.totalHeight || 0);
        console.log(dimensions.contentHeight, '12345表格内容高度');
        this.tableHeight = (this.tableData.length > 0 ? maxTableHeight : 300) + 'px';
      });
    },
    //显示弹窗
    showDilogBtn(field) {
      this[field] = !this[field];
    },
    //选择表格数据
    handleSelectionChange(table) {
      this.multipleSelection = Object.assign([], table);
    },
    //点击批量删除
    delteDataBtn() {
      if (this.multipleSelection.length === 0) {
        return this.$message.warning('请选择需要删除的数据');
      }
      this.showDilogBtn('deleteDialogVisible');
    },
    //删除
    delBtnClick(val) {
      this.selectedRow = JSON.parse(JSON.stringify(val));
      this.showDilogBtn('deleteDialogVisible');
    },
    //审核
    auditBtnClick(val) {
      this.selectedRow = JSON.parse(JSON.stringify(val));
      this.showDilogBtn('auditDialogVisible');
    },
    //批量审核
    batchAuitBtn() {
      if (this.multipleSelection.length === 0) {
        return this.$message.warning('请选择需要审核的数据');
      }
      this.showDilogBtn('auditDialogVisible');
    },
    editBtnClick(item) {
      this.addParams = Object.assign({}, item);
      this.showDilogBtn('addDialogVisible');
    },
    //修改页码
    changePage(pageNum) {
      this.params.pageNum = pageNum;
      this.getDataList();
    },
    //修改每页显示的条数
    changeSize(size) {
      this.params.pageSize = size;
      this.params.pageNum = 1;
      this.getDataList();
    },
    //搜索品牌
    handleSearch() {
      // this.params.pageNum = 1;
      // this.params.pageSize = 20;
      this.getDataList();
    }
  }
};
